package com.neuedu.his.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neuedu.his.mapper.ChargeMapper;
import com.neuedu.his.po.Charge;
import com.neuedu.his.service.ChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChargeServiceImpl extends ServiceImpl<ChargeMapper, Charge> implements ChargeService {

    @Autowired
    private ChargeMapper chargeMapper;

    @Override
    public boolean chargeItem(Integer id) {
        // 更新项目状态为已收费
        Charge charge = chargeMapper.selectById(id);
        if (charge != null) {
            charge.setState(2);
            return chargeMapper.updateById(charge) > 0;
        }
        return false;
    }

    @Override
    public boolean chargeAll(List<Integer> ids) {
        for (Integer id : ids) {
            Charge charge = chargeMapper.selectById(id);
            if (charge != null) {
                charge.setState(2);
                if (chargeMapper.updateById(charge) <= 0) {
                    return false;
                }
            }
        }
        return true;
    }
}